/*
 * @Description: 
 * @Author: 周永强
 * @Date: 2021-12-01 19:39:52
 * @LastEditTime: 2022-11-17 15:50:15
 * @LastEditors:  
 */
import { downloadFile, reqEchartList } from '../../service/echarts'
import { saveAs } from 'file-saver';
import { message } from 'antd';
const Model = {
    namespace: 'echarts',
    state: {
        list: [],
        total: 0
    },
    effects: {
        *downloadFile({ payload }, { put, call }) {
            const res = yield call(downloadFile, payload)
            console.log(res)
            saveAs(res, 'test.zip')
        },
        *getEchartInfo({ payload }, { put, call }) {
            const res = yield call(reqEchartList, payload)
            if (res.code == 200) {
                yield put({
                    type: 'saveEchartList',
                    payload: res.raw
                })
                yield put({
                    type: 'saveEchartTotal',
                    payload: res.total
                })
            }
        }
    },
    reducers: {
        saveEchartList(state, { payload }) {
            return { ...state, list: payload }
        },
        saveEchartTotal(state, { payload }) {
            return { ...state, total: payload }
        }
    }
}

export default Model